<#assign module="driver"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
</@override>
<@override name="body">

	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					服务人员充值：${driver.realname}（工号： ${driver.username}），帐号余额：${driver.virtual} ， 司机可代付金额:
					${helppayMoney}
				</div>
				<div class="panel-body">
    				<form id="submit_form" action="${ctx}/driver/money" class="form-horizontal" method="post">
					<input type="hidden" name="driverid" value="${driver.id}">
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>余额充值（元）：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="money" name="money" type="number" required autofocus/>
		                    </div>
		                    <div class="col-sm-5">
				            	<span id="tip4Desc">本次充值金额,如：100。输入负数表示扣费。0元不生成记录。充值和扣费金额会计入司机的可代付金额中</span>
				            </div>
		                </div>

						<div class="form-group">
							<label class="col-sm-3 control-label"><em>*</em>代付金额充值（元）：</label>
							<div class="col-sm-3">
								<input class="form-control" id="helppay" name="helppay" type="number" required autofocus/>
							</div>
							<div class="col-sm-5">
								<span id="tip4Desc">本次充值金额,如：100。输入负数表示扣费。0元不生成记录。充值和扣费金额会计入司机的可代付金额中</span>
							</div>
						</div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">备注：</label>
		                    <div class="col-sm-3">
		                        <textarea class="form-control" cols="20" id="memo" name="memo" rows="2" maxlength="200"></textarea>
		                    </div>
		                    <div class="col-sm-5">   
				            	<span id="tip4Desc">本次充值（扣费）说明，最多输入200个字符<br/>还可输入<span id="leftWords" style="color:red;">200</span>个字符</span>
				            </div>
		                </div>
		                
		                <div class="form-group" style="margin-left:10px;">
			                <label class="col-sm-3 control-label"></label>
			                <@shiro.hasPermission name='drivermoney'>
			                <input type="button" id="submit_button" class="btn btn-primary" value="保存">
			                </@shiro.hasPermission>
			                <input type="button" class="btn btn-default" onclick="window.location.href = '${ctx}/driver/list';" value="返回">
			            </div>
					</form>
					
        		</div>
			</div>
			
		</div>
		
	</div>
	
	<div class="row" id = "app">
		<div class="col-md-12">
			<div class="panel panel-default" style="height: 100px;" >
				<div class="panel-heading">
					消费及充值历史清单
			    </div>
				<div class="panel-body">
					<form class="form-inline" id="SearchForm" method="get">
					    <div class="form-group">
			                <input class="form-control" id="startTime" name="startTime" placeholder="开始时间" readonly="readonly" type="text" value="${start?string('yyyy-MM-dd')}">
			            </div>
			            <div class="form-group">
			                <input class="form-control" id="endTime" name="endTime" placeholder="结束时间" readonly="readonly" type="text" value="${end?string('yyyy-MM-dd')}">
			            </div>
			            <div class="form-group">
			                <input type="submit" class="btn btn-default" value="查询">
			            </div>

						<div class="form-group">
							<tag color="success" type="dot">产值：<span style="font-size: 14px; font-weight: normal;">${allPayments}</span>&nbsp;元</tag>
						</div>
						<div class="form-group" style="margin-left:60%">
							<button type="button" class="pull-right btn btn-primary" onclick="window.location='${ctx}/driver/paymentsExport/${driver.id}';"><i class="glyphicon glyphicon-save"></i>&nbsp;导出记录</button>
						</div>
					</form>
				</div>
			</div>	
	    </div>	
    </div>

    <div class="row">
        <div class="col-xs-12">
            <div class="panel panel-primary">
                <div class="table-responsive">
                    <table class="table table-hover table-striped">
                        <thead>
                        <tr style="font-size:14px;">
                            <th>时间</th>
                            <th>类型</th>
                            <th>订单号</th>
                            <th>金额(元)</th>
                            <th>操作后余额(元)</th>
                            <th>充值/消费方式</th>
                            <th>操作人</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#if (page.content)?? >
                            <#list page.content as data>
                                <tr>
                                    <td>${data.happend?string("yyyy-MM-dd HH:mm:ss")}</td>
                                    <td>
                                        <#if (data.operateType)??>
                                        <span>可代付金额<span>
                                                    <#else>
                                                    <span>余额<span>
                                        </#if>
                                    </td>
                                    <td>
                                        <#if (data.orderId)?? && (data.orderNumber)??>
                                            <#if data.orderType==0>
                                                <a href="javascript:;"
                                                   onclick="window.location='${ctx}/order/detail/${data.orderId}';"
                                                   class="btn-link">****${data.orderNumber?substring(8)}</a>
                                            <#elseif data.orderType==1>
                                                <a href="javascript:;"
                                                   onclick="window.location='${ctx}/zhuanche/detail/${data.orderId}';"
                                                   class="btn-link">****${data.orderNumber?substring(4)}</a>
                                            <#elseif data.orderType==2 && data.orderNumber.length() == 14>
                                                <a href="javascript:;"
                                                   onclick="window.location='${ctx}/errand/up/detail/${data.orderId}';"
                                                   class="btn-link">****${data.orderNumber?substring(4)}</a>
                                            <#elseif data.orderType==2 && data.orderNumber.length() == 12>
                                                <a href="javascript:;"
                                                   onclick="window.location='${ctx}/errand/detail/${data.orderId}';"
                                                   class="btn-link">****${data.orderNumber?substring(4)}</a>
                                            <#elseif data.orderType==4>
                                                <a href="javascript:;"
                                                   onclick="window.location='${ctx}/freight/orderDetails/${data.orderId}';"
                                                   class="btn-link">****${data.orderNumber?substring(4)}</a>
                                            <#elseif data.orderType==5>
                                                <a href="javascript:;"
                                                   onclick="window.location='${ctx}/zhuanxian/detail/${data.orderId}';"
                                                   class="btn-link">****${data.orderNumber?substring(4)}</a>
                                            </#if>
                                        <#else>

                                        </#if>
                                    </td>
                                    <#if data.rcType??>
                                        <#if data.rcType==0>
                                            <td>
                                                <span style="color:#00EC00;font-weight:700;">+${data.money?if_exists}</span>

                                            </td>
                                            <td>
                                                <span style="color:#00EC00;font-weight:700;">${data.afterMoney?if_exists}</span>
                                            </td>
                                        </#if>
                                        <#if data.rcType==1>
                                            <td>
												<#if data.money lt 0>
													<span style="color:#EA0000;font-weight:700;">${data.money?if_exists}</span>
												<#else>
													<span style="color:#EA0000;font-weight:700;">-${data.money?if_exists}</span>
												</#if>
                                            </td>
                                            <td>
                                                <span style="color:#EA0000;font-weight:700;">${data.afterMoney?if_exists}</span>
                                            </td>
                                        </#if>
                                        <#if data.rcType==2>
                                            <td>
                                                <span style="color:#00EC00;font-weight:700;">+${data.money?if_exists}</span>
                                            </td>
                                            <td>
                                                <span style="color:#00EC00;font-weight:700;">${data.afterMoney?if_exists}</span>
                                            </td>
                                        </#if>
                                        <#if data.rcType==3>
                                            <td>
                                                <span style="color:#00EC00;font-weight:700;">+${data.money?if_exists}</span>
                                            </td>
                                            <td>
                                                <span style="color:#00EC00;font-weight:700;">${data.afterMoney?if_exists}</span>
                                            </td>
                                        </#if>
                                    <#else>
                                        <td>
                                            <#if data.money gt 0>
                                                <span style="color:#00EC00;font-weight:700;">+${data.money?if_exists}</span>
                                            <#else>
                                                <span style="color:#EA0000;font-weight:700;">${data.money?if_exists}</span>
                                            </#if>
                                        </td>
                                        <td></td>
                                    </#if>

                                    <#--<#if data.rcType==0>-->
                                    <#--<td><span style="color:#00EC00;font-weight:700;">+${data.money?if_exists}</span></td>-->
                                    <#--<td><span style="color:#00EC00;font-weight:700;">${data.afterMoney?if_exists}</span></td>-->
                                    <#--<#else>-->
                                    <#--<td><span style="color:#EA0000;font-weight:700;">-${data.money?if_exists}</span></td>-->
                                    <#--<td><span style="color:#EA0000;font-weight:700;">${data.afterMoney?if_exists}</span></td>-->
                                    <#--</#if>-->

                                    <td>
                                        ${data.recordTypeStr?if_exists}
                                    </td>
                                    <td>${data.operating?if_exists}</td>
                                    <td style="max-width:450px;">${data.memo?if_exists}</td>
                                </tr>
                            </#list>
                        </#if>
                        </tbody>
                    </table>
                    <#if page.totalElements??>
                        <ul class="pagination pull-right pagination-sm">
                            <li><a>共 ${page.totalElements} 条数据</a></li>
                            <@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/driver/money/${driver.id}">
                                <@pg.param name="startTime" value="${start?string('yyyy-MM-dd')}"/>
                                <@pg.param name="endTime" value="${end?string('yyyy-MM-dd')}"/>
                                <@pg.index>
                                    <@pg.first>
                                        <li><a href="${pageUrl}">&laquo;</a></li>
                                    </@pg.first>
                                    <@pg.prev>
                                        <li><a href="${pageUrl}">&lsaquo;</a></li>
                                    </@pg.prev>
                                    <@pg.pages>
                                        <#if  currentPageNumber == pageNumber >
                                            <li class="active"><a href="#">${pageNumber}</a></li>
                                        <#else>
                                            <li><a href="${pageUrl}">${pageNumber}</a></li>
                                        </#if>
                                    </@pg.pages>
                                    <@pg.next>
                                        <li><a href="${pageUrl}">&rsaquo;</a></li>
                                    </@pg.next>
                                    <@pg.last>
                                        <li><a href="${pageUrl}">&raquo;</a></li>
                                    </@pg.last>
                                </@pg.index>
                            </@pg.pager>
                        </ul>
                    </#if>
                </div>
            </div>
        </div>
    </div>


</@override>
<@override name="footer">
<script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript">
	var vue = new Vue({
		el: "#app"
	})
	$(document).ready(function(){
	
		$("#startTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
		$("#endTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
	
		$("#memo").keyup(function(){
			$("#leftWords").html(200-$(this).val().length);
		});

        $("#money").bind("input propertychange",function(){
            var money = parseFloat($(this).val());
            if(money>100000){
                $(this).val("");
                $.scojs_message("输入金额请在十万以内", $.scojs_message.TYPE_ERROR);
            }
        });
		$("#submit_button").click(function(){
			var money=$("#money").val();
			var helppay = $("#helppay").val();
			if(money.length>0 || helppay.length > 0){

				var reg=/^(-?\d+)(.[0-9]{0,2})?$/;
				if(!reg.test(money) && !reg.test(helppay)){
			       $.scojs_message('无效的金额！', $.scojs_message.TYPE_ERROR);
			       return false;
			    }

			    if(money>10000){
			    	$.scojs_message('金额过大！', $.scojs_message.TYPE_ERROR);
			    	return false;
			    }
				if(helppay>10000){
					$.scojs_message('金额过大！', $.scojs_message.TYPE_ERROR);
					return false;
				}

				if(money >= 0){
					console.log(money);
				    var confirm = $.scojs_confirm({
                    		          content: "确认要充值余额"+money+"元吗？",
                    		          action:function(){
                    		          	$("#submit_form").submit();
                    		          }
                    		        });
					confirm.show();
				}else{
					console.log(money);
				    var confirm = $.scojs_confirm({
                                      content: "确认要扣费余额"+money+"元吗？",
                                      action:function(){
                                        $("#submit_form").submit();
                                      }
                                    });
					confirm.show();
				}

				if(helppay >= 0){
					var confirm = $.scojs_confirm({
						content: "确认要充值代付金额"+helppay+"元吗？",
						action:function(){
							$("#submit_form").submit();
						}
					});
					confirm.show();
				}else{
					var confirm = $.scojs_confirm({
						content: "确认要扣费代付金额"+helppay+"元吗？",
						action:function(){
							$("#submit_form").submit();
						}
					});
					confirm.show();
				}
			}
			else{
				$.scojs_message('请填写一个金额！', $.scojs_message.TYPE_ERROR);
			}
		});
		
	});
</script>
</@override>
<@extends name="../layout.ftl"/>